//
//  UploadTicketOrderModel.m
//  ImGuider
//
//  Created by 王鹏宇 on 2018/2/1.
//  Copyright © 2018年 imguider. All rights reserved.
//

#import "UploadTicketOrderModel.h"

@implementation UploadTicketOrderModel

+ (NSDictionary *)modelCustomPropertyMapper {
    
    return @{@"ID" : @"id"};
}
+ (NSDictionary *)modelContainerPropertyGenericClass {
    
    return @{@"visitors": [TicketOrderRecordModel class],@"tickets":[CompeleteTicketeModel class]};
}

- (NSString *)orderdate {
    
    if(_orderdate.length >= 10){
        
        NSString * str = [_orderdate substringToIndex:10];
        return str;
    }
    return @"";
}

- (NSString *)APM {
    
    if(_APM.length == 0){
        
        return @"";
    }
    return _APM;
}
- (NSArray *)pictureArray {
    
    return [self.pictures componentsSeparatedByString:@","];
}
- (TicketMemberInfoModel *)contact {
    
    if (!_contact) {
        
        _contact = [[TicketMemberInfoModel alloc] init];
    }
    
   return  _contact;
}

- (NSMutableArray<TicketOrderRecordModel *> *)visitors {
    
    if (!_visitors) {
        
        _visitors = [NSMutableArray new];
    }
    
    return _visitors;
}

- (NSMutableArray<TicketMemberInfoModel *> *)Allpersons {
    
    if (!_Allpersons) {
        _Allpersons = [NSMutableArray new];
    }
    [_Allpersons removeAllObjects];
    for (TicketOrderRecordModel * model in self.visitors) {
        
        if (model.size.integerValue == 0) {
            
            [_Allpersons addObjectsFromArray:model.persons];
        }
    }
    
    return _Allpersons;
}

- (NSString *)orderInfo {
    
    NSMutableString * str = [NSMutableString new];
    for (TicketOrderRecordModel * model in self.visitors) {
        
        switch (model.tickettype.integerValue) {
            case AdultTicket:
            {
                [str appendString:[self getTheTicketInfoWith:model headerStr:MYLocalizedString(@"TICKET_TYPE_ADULT", nil)]];
            }
                break;
            case ChildrenTicket:
            {
                
                [str appendString:[self getTheTicketInfoWith:model headerStr:MYLocalizedString(@"TICKET_TYPE_CHILDREN", nil)]];
            }
                break;
            case ElderTicket:
            {
                 [str appendString:[self getTheTicketInfoWith:model headerStr:@"长者"]];
            }
                break;
            case MemberTicket:
            {
                 [str appendString:[self getTheTicketInfoWith:model headerStr:@"团体"]];
            }
                break;
            default:
                break;
        }
    }
    
    
    return str;
}


- (NSString *)getTheTicketInfoWith:(TicketOrderRecordModel *)model headerStr:(NSString *)str{
    
    
    if (model.size.integerValue == 0) {
        if(model.persons.count == 0){
            return @"";
        }else{
       return [NSString stringWithFormat:@"%@X%ld ",str,model.persons.count];
        }
    }else{
        return [NSString stringWithFormat:@"%@X%ld ",str,model.size.integerValue];
    }
}

- (NSInteger)PersonNum{
    
    NSInteger num = 0;
    for (TicketOrderRecordModel * model in self.visitors) {
        
        switch (model.tickettype.integerValue) {
            case AdultTicket:
            {
                num += [self getTheTicketNumWith:model];
            }
                break;
            case ChildrenTicket:
            {
                
               num += [self getTheTicketNumWith:model];
            }
                break;
            case ElderTicket:
            {
                num += [self getTheTicketNumWith:model];
            }
                break;
            case MemberTicket:
            {
                num += [self getTheTicketNumWith:model];
            }
                break;
            default:
                break;
        }
    }
    
    
    return num;
}

- (NSInteger)getTheTicketNumWith:(TicketOrderRecordModel *)model {
    
    
    if (model.size.integerValue == 0) {
        
        return model.persons.count;
    }else{
        return model.size.integerValue;
    }
}
@end
